package com.tricode.ile.training.task.ESAD;

class CustomersInDB {
    Connection conn;

    Customer getCustomer(String idNumber) {

        PreparedStatement st = getStatement("select * from customer where ID=?", prepareCustomerId(idNumber));

        try {
            ResultSet rs = st.executeQuery();
            // ...
        } finally {
            st.close();
        }
        return null;//this line is here just for compilation
    }

    void addCustomer(Customer customer) {
        PreparedStatement st = getStatement(
                "insert into customer values(?,?,?,?)",
                prepareCustomerId(customer.getIDNumber()),
                customer.getName()
        );
        try {
            // ...
            st.executeUpdate();
            // ...
        } finally {
            st.close();
        }
    }

    private PreparedStatement getStatement(String query, String... params) {
        PreparedStatement st = conn.prepareStatement(query);

        for (int i = 0; i < params.length; i++) {
            st.setString(i + 1, params[i]);
        }

        return st;
    }

    private String prepareCustomerId(String id) {
        return id
                .replace('-', ' ')
                .replace('(', ' ')
                .replace(')', ' ')
                .replace('/', ' ');
    }
}

class Customer {

    public String getIDNumber() {
        // TODO Auto-generated method stub
        return null;
    }

    public String getName() {
        // TODO Auto-generated method stub
        return null;
    }
}

class Connection {

    public PreparedStatement prepareStatement(String string) {
        // TODO Auto-generated method stub
        return null;
    }



}

class PreparedStatement {

    public void setString(int i, String replace) {
        // TODO Auto-generated method stub

    }

    public void executeUpdate() {
        // TODO Auto-generated method stub

    }

    public void close() {
        // TODO Auto-generated method stub

    }

    public ResultSet executeQuery() {
        // TODO Auto-generated method stub
        return null;
    }
}

class ResultSet {
}